package spring.data.jpa.repository;

import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import spring.data.jpa.entity.Department;
import spring.data.jpa.entity.Employee;
import spring.data.jpa.repository.support.template.TemplateParam;
import spring.data.jpa.repository.support.template.TemplateQuery;

public interface DepartmentRepository extends CommonJpaRepository<Department, Long> {
    void findByName(String name);

    @TemplateQuery
    void addDept(@TemplateParam("dept") Department dept);

    @TemplateQuery
    List<Department> findByParams();

    @TemplateQuery
    List<Department> findByParams(@TemplateParam("name") String name, Pageable pageable);

    @TemplateQuery(name = "findByCompositeParams")
    List<Department> findByParams(@TemplateParam("dept") Department dept, @TemplateParam("name") String name,
            Pageable pageable);

    @TemplateQuery
    List<Department> findByEmployeeExist(@TemplateParam("dept") Department dept, @TemplateParam("emp") Employee employee);

    @TemplateQuery(nativeQuery = false)
    List<Department> findByEmployeeExistJpql(@TemplateParam("name") String name);
    
    @TemplateQuery
    List<Department> findByParameterList(@TemplateParam("name") String name);

    @Query(value = "from Department t where t.name like :name and t.number > :number")
    List<Department> findByParams(@Param("name") String name, @Param("number") int number);
}
